﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace IdeaNMR.Shared
{
    public static class Sanitar
    {
        public static UserInputField Name = new UserInputField()
        {
            MaxLength = 50,
            ValidationRegex = @"^[a-zA-Z0-9_]([a-zA-Z0-9]|\.|-| |_){2,49}$",
            ErrorMsg = "The name must start with alphanumeric character and can contain only alphanumeric, space and '_', '-' characters. It should be 3-50 characters long."
        };

        public static UserInputField Type = new UserInputField()
            {
                MaxLength = 50,
                ValidationRegex = @"^[a-zA-Z0-9_]([a-zA-Z0-9]|-| |_|#|\+){2,49}$",
                ErrorMsg = "The type must start with alphanumeric character and can contain only alphanumeric, '#', '+', '_' and '-' characters. It should be 3-50 characters long."
            };

        public static UserInputField Remark = new UserInputField()
        {
            MaxLength = 2000,
            ValidationRegex = @"^(.|\s){1,2000}$",
            ErrorMsg = "Remark must be present and not longer than 2000 symbols including white space characters."
        };
        public static UserInputField Script = new UserInputField()
        {
            MaxLength = 50000,
            ValidationRegex = @"^(.|\s){0,50000}$",
            ErrorMsg = "Script should not be longer than 50000 characters."
        };
        public static UserInputField Content = new UserInputField()
        {
            MaxLength = 50000,
            ValidationRegex = @"^(.|\s){0,50000}$",
            ErrorMsg = "Content should not be longer than 50000 characters."
        };

        // ALISTAIR: 12/07/2011
        // Added Spinach user input field
        public static UserInputField SpinachMacro = new UserInputField()
        {
            MaxLength = 50000,
            ValidationRegex = @"^(.|\s){0,50000}$",
            ErrorMsg = "Content should not be longer than 50000 characters."
        };

        public static UserInputField Analytics = new UserInputField()
        {
            MaxLength = 50000,
            ValidationRegex = @"^(.|\s){0,50000}$",
            ErrorMsg = "Analytics parameters must not be longer thant 50000 characters."
        };

        public static UserInputField Username = new UserInputField()
        {
            MaxLength = 50,
            ValidationRegex = @"^([A-Z])([a-z]){0,50}$",
            ErrorMsg = "Human name must start with capital letter, should contain not more then 50 english alphabet characters."
        };

        public static UserInputField ContactPerson = new UserInputField()
        {
            MaxLength = 128,
            ValidationRegex = @"^([a-zA-Z]|\.| ){1,128}$",
            ErrorMsg = "Contact should me not longer then 128 symbol and can contain only letters, '.' and space characters."
        };

        public static UserInputField ContactMail = new UserInputField()
        {
            MaxLength = 1000,
            ValidationRegex = @"^\b[\w\.-]+@[\w\.-]+\.\w{2,4}\b$",
            ErrorMsg = "Must be valid email address."
        };

        public static UserInputField Buffer = new UserInputField()
        {
            MaxLength = 1000,
            ErrorMsg = "Buffer should not be longer than 1000 characters.",
            ValidationRegex = @"^.{1,1000}$"
        };

        public static UserInputField Labeling = new UserInputField()
        {
            MaxLength = 1000,
            ErrorMsg = "Isotope names separated by semicolumns.",
            ValidationRegex = @"^Unlabeled|((15N|13C|2H|31P)(;|15N|13C|2H|31P|\s*)*)$"
        };

        public static UserInputField Frequency = new UserInputField()
        {
            MaxLength = 50,
            ErrorMsg = "Frequency must be a floating-point number.",
            ValidationRegex = @"^[0-9]+(?:.[0-9]+)?$"
        };

        public static UserInputField Location = new UserInputField()
        {
            MaxLength = 50,
            ErrorMsg = "Location must be not longer than 50 characters.",
            ValidationRegex = @"^.{1,50}$"
        };

        public static UserInputField Dimensionality = new UserInputField()
        {
            MaxLength = 0,
            ErrorMsg = "Please choose dimensionality.",
            ValidationRegex = string.Empty
        };

        public static UserInputField Relaxation = new UserInputField()
        {
            MaxLength = 50,
            ErrorMsg = "Relaxation Rate must be a real positive number.",
            ValidationRegex = @"^(\d*(\.)\d*|0?(\.)\d*[1-9]\d*|[1-9]\d*)$"
        };

        // ALISTAIR 23/05/2011: Add TuaC input field to validation
        // By default - using same validation as for relaxation parameter
        public static UserInputField TauC = new UserInputField()
        {
            MaxLength = 50,
            ErrorMsg = "TauC must be a real positive number.",
            ValidationRegex = @"^(\d*(\.)\d*|0?(\.)\d*[1-9]\d*|[1-9]\d*)$"
        };

        // ALISTAIR 03/04/2012: Add S/N from 1D input field to validation
        // By default - using same validation as for relaxation parameter
        public static UserInputField OneDimSigToNoise = new UserInputField()
        {
            MaxLength = 50,
            ErrorMsg = "Usage: 1D Signal-To-Noise must be a positive number.",
            ValidationRegex = @"^(\d*(\.)\d*|0?(\.)\d*[1-9]\d*|[1-9]\d*)$"
        };

    }

    public struct UserInputField
    {
        public int MaxLength { get; internal set; }
        public string ValidationRegex { get; internal set; }
        public string ErrorMsg { get; internal set; }
    }
}
